package org.budo.validation.validator.impl;

import java.lang.annotation.Annotation;

import org.budo.validation.exception.BudoLengthValidationException;
import org.hibernate.validator.constraints.Length;

/**
 * @author lmw
 */
public class LengthValidator extends SizeValidator {
    public void validate(Annotation annotation, Integer parameterIndex, String parameterName, Object argumentValue) {
        if (null == argumentValue) {
            return;
        }

        Integer len = this.size(argumentValue);

        Length length = (Length) annotation;
        if (null != len && (len > length.max() || len < length.min())) {
            throw new BudoLengthValidationException(parameterIndex, parameterName, length, argumentValue);
        }
    }
}